import { computed } from "vue";
import { useMutation } from "@tanstack/vue-query";
import { resumeApi } from "../api";
import type { ResumeData, Response } from "../types";
import { ElMessage } from "element-plus";

export function useResumeQuery() {
  const postResumeMutation = useMutation({
    mutationFn: async (data: ResumeData) => {
      const res = await resumeApi.PostResume(data);
      return res;
    },
    onSuccess: (result: Response) => {
      ElMessage(result.message);
    },
    onError: (error) => {
      throw new Error(error.message);
    }
  });

  return {
    postResumeMutation,
    isLoading: computed(() => postResumeMutation.isPending.value),
    isDownloading: computed(() => postResumeMutation.isPending.value)
  };
}
